﻿#ifndef OEASYPROXY_H
#define OEASYPROXY_H

#ifndef NO_WIDGETS
#include <QMainWindow>
#include <QTextEdit>
#endif
#include <QTimer>
#include <QObject>
#include "oeasycommon.h"
#include "configfile.h"
#include "access.h"
#include "facerecvpic.h"
#include "ipc.h"
#include "nvr.h"
#include "targetcli.h"
#include "intercom.h"
#include "uploadpicvideo.h"

#ifndef NO_WIDGETS
namespace Ui {
class OeasyProxy;
}
#endif

typedef struct tagSTRUCT_IPC_NVR_LIST {
    void *ipcList;
    void *nvrList;
}STRUCT_IPC_NVR_LIST;

#ifndef NO_WIDGETS
class OeasyProxy : public QMainWindow
#else
class OeasyProxy : public QObject
#endif
{
    Q_OBJECT

public:
#ifndef NO_WIDGETS
    explicit OeasyProxy(QWidget *parent = 0);
#else
    explicit OeasyProxy(QObject *parent = 0);
#endif
    ~OeasyProxy();
private:
    void createRecordFolder();

private:
#ifndef NO_WIDGETS
    Ui::OeasyProxy *ui;
#endif
    ConfigFile m_cfg;
    QList<IPC *> m_ipcList;
    QList<NVR *> m_nvrList;
    FaceRecvPic m_picServer;
    Intercom m_intercom;
    Access m_access;
    TargetCli m_targetCli;
    UploadPicVideo m_upload;
    QNetworkAccessManager m_picManager;
    QNetworkAccessManager m_reportManager;
    QNetworkAccessManager m_bigDataManager;
    QMap<QNetworkReply *, QPair<QByteArray, int>> m_postMap;
    QTimer m_timer;
	STRUCT_IPC_NVR_LIST m_ipc_nvrList;

    void initIpc();
    void initLog();
    void post(QNetworkAccessManager &, QNetworkRequest, const QPair<QByteArray, int> &);

signals:
    void snapAndGetVideo(const QString data,int channel,LONG lRealPlayHandle);

public slots:
    void onLogChanged();
    void onPostPic(const QByteArray &);
    void onPostReport(const QByteArray &);
    void onPostBigData(const QByteArray &);
    void onPostReadyRead();
    void onPostFinish(QNetworkReply *r);
    void onTimeout();
    void onOpenDoor(QByteArray data,QString mac);
};

#endif // OEASYPROXY_H
